<?php

namespace Yolo\Errors;

use Hyperf\Contract\MessageBag;

class InvalidParameterException extends RpcException
{
    protected string $symbol = 'invalid_parameter';

    protected $message = 'Invalid parameter.';

    protected int $statusCode = 400;

    protected ?MessageBag $errors = null;

    public function setErrors(MessageBag $errors): void
    {
        $this->errors = $errors;
    }

    public function getErrors(): MessageBag
    {
        return $this->errors;
    }

    public function json(): array
    {
        $json =  parent::json();

        $json['invalidParameterKeys'] = $this->errors->keys();
        $json['invalidParameterMessages'] = $this->errors->getMessages();
        return $json;
    }
}
